package com.xiaoluo.a19_zxing;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;


/**
 * @ Created on: 2020/10/21
 * @Author: LEGION XiaoLuo
 * @ Description:
 */
public class LoadingView extends LinearLayout {
    private TextView mNameView;
    private View mStartStub;
    private View mEndStub;

    public LoadingView(Context context) {
        super(context);
        init();
    }

    private void init() {
        Log.i("xlj1130", "init: ");

        setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, UiUtil.div(80)));
        setBackground(ThemeUtils.getDrawable(Color.parseColor("#F2FFFFFF"), UiUtil.div(40)));
        setOrientation(HORIZONTAL);

        mStartStub = new View(getContext());
        LayoutParams startStubParams = new LayoutParams(UiUtil.div(40), ViewGroup.LayoutParams.WRAP_CONTENT);
        addView(mStartStub, startStubParams);

        TextView comeTextView = new TextView(getContext());
        comeTextView.setTextSize(UiUtil.dpi(32));
        comeTextView.setIncludeFontPadding(false);
        comeTextView.setTextColor(Color.parseColor("#0B0B0B"));
        comeTextView.setText("来自用户");
        LayoutParams comeParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, UiUtil.div(32));
        comeParams.gravity = Gravity.CENTER_VERTICAL;
        addView(comeTextView, comeParams);

        mNameView = new TextView(getContext());
        LayoutParams nameParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        nameParams.gravity = Gravity.CENTER_VERTICAL;
        nameParams.leftMargin = UiUtil.div(20);
        mNameView.setTextSize(UiUtil.dpi(32));
        mNameView.setTextColor(Color.parseColor("#FF5525"));
        addView(mNameView, nameParams);

        TextView endTextView = new TextView(getContext());
        endTextView.setTextSize(UiUtil.dpi(32));
        endTextView.setTextColor(Color.parseColor("#0D0D0D"));
        endTextView.setText("的投屏");
        LayoutParams endTextParams = new LayoutParams(UiUtil.div(96), ViewGroup.LayoutParams.WRAP_CONTENT);
        endTextParams.gravity = Gravity.CENTER_VERTICAL;
        endTextParams.leftMargin = UiUtil.div(20);
        addView(endTextView, endTextParams);

        mEndStub = new View(getContext());
        LayoutParams endStubParams = new LayoutParams(UiUtil.div(40), ViewGroup.LayoutParams.WRAP_CONTENT);
        addView(mEndStub, endStubParams);

    }


    public void setUserText(String url, String useNameStr) {
        Log.i("xlj1130", "setUserText: ");
        String hideNumStr = useNameStr;
        mNameView.setText("「" + hideNumStr + "」");
        if (hideNumStr.length() == 0) {
            mStartStub.getLayoutParams().width = UiUtil.div(40 + 115);
            mEndStub.getLayoutParams().width = UiUtil.div(40 + 115);
            requestLayout();
        }
    }
}
